package com.jf.service.impl;

import com.jf.bean.Banner;
import com.jf.dao.BannerDao;
import com.jf.dao.impl.BannerDaoImpl;
import com.jf.service.BannerService;
import com.jf.util.PageInfo;
import com.jf.util.ResultJson;

import java.util.List;

public class BannerServiceImpl implements BannerService {
    private BannerDao bannerDao = new BannerDaoImpl();
    @Override
    public ResultJson getPage(PageInfo pageInfo, Banner banner) {
        List<Banner> list = bannerDao.getPage(pageInfo, banner);
        int count = bannerDao.getCount(banner);
        pageInfo.setPageData(list,count);
        return ResultJson.success(pageInfo);
    }

    @Override
    public ResultJson saveOrUpdate(Banner banner) {
        int result;
        if(banner.getId() == null){
            result = bannerDao.addSelect(banner);
        }else{
            result = bannerDao.updateSelect(banner);
        }
        return result > 0 ?ResultJson.success():ResultJson.error("操作失败");
    }

    @Override
    public ResultJson delete(int[] ids) {
        int result = bannerDao.batchDelete(ids);
        return result == ids.length ? ResultJson.success():ResultJson.error("删除异常");
    }

    @Override
    public ResultJson info(int id) {
        return ResultJson.success(bannerDao.getById(id));
    }

    @Override
    public ResultJson getList() {
        return ResultJson.success(bannerDao.getList());
    }
}
